package com.dnjn.happiness.system.model;

//import com.baomidou.mybatisplus.annotation.TableField;
import com.dnjn.happiness.common.core.annotation.Excel;
import com.dnjn.happiness.common.core.annotation.Excels;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.xss.Xss;
import com.dnjn.happiness.system.api.domain.SysDept;
import com.dnjn.happiness.system.api.domain.SysRole;
import com.dnjn.happiness.system.api.domain.SysUser;
import com.dnjn.happiness.system.sensitive.SensitiveEncrypt;
import com.dnjn.happiness.system.sensitive.SensitiveType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author happy
 */

@ToString
@Getter
@Setter
public class SysUserDTO {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号")
    private Long userId;

    /**
     * 部门ID
     */
    @Excel(name = "部门编号", type = Excel.Type.IMPORT)
    private Long deptId;
    @Excel(name = "工号")
    private String empno;
    @Excel(name = "SAP流水号")
    private String sapNo;

    @Excel(name = "职级")
    private String positionLadder;
    @Excel(name = "职等")
    private Integer positionLevel;
    @Excel(name = "入职日期", width = 30, dateFormat = "yyyy-MM-dd")
    private LocalDate empDate;


    /**
     * 用户账号
     */
    @Xss(message = "用户账号不能包含脚本字符")
    @Excel(name = "登录名称")
    private String userName;

    /**
     * 用户昵称
     */
    @Excel(name = "姓名")
    private String nickName;

    /**
     * 用户邮箱
     */
    @Excel(name = "用户邮箱")
    @SensitiveEncrypt(type = SensitiveType.EMAIL)
    private String email;

    /**
     * 手机号码
     */
    @SensitiveEncrypt(type = SensitiveType.MOBILE_PHONE)
    @Excel(name = "手机号码")
    private String phonenumber;

    /**
     * 用户性别
     */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    @Excel(name = "用户生日")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate birthday;
    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 个人履历地址
     */
    private String resumeurl;


    /**
     * 密码
     */
//    @SensitiveEncrypt(type = SensitiveType.PASSWORD)
//    @JSONField(serialize = false)
    @JsonIgnore
    private String password;

    /**
     * 帐号状态（0正常 1停用）
     */
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    private String delFlag;

    /**
     * 最后登录IP
     */
//    @Excel(name = "最后登录IP", type = Excel.Type.EXPORT)
    private String loginIp;

    /**
     * 最后登录时间
     */
//    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
    private LocalDateTime loginDate;

    /**
     * 部门对象
     */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Excel.Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Excel.Type.EXPORT)
    })
    private SysDept dept;

    /**
     * 当前用户父级部门信息
     */
    // @TableField(exist = false)
    private SysDept leaderDept;

    /**
     * 角色对象
     */
    private List<SysRole> roles;

    /**
     * 角色组
     */
    private Long[] roleIds;

    /**
     * 岗位组
     */
    private Long[] postIds;

    /**
     * 岗位组
     */
    // @TableField(exist = false)
    private String postNames;

    /**
     * 角色ID
     */
    private Long roleId;

    /**
     * 微信open_id
     */
    private String openId;

    /**
     * 微信union_id
     */
    private String unionId;

    /**
     * 婚姻 未婚、已婚、离异或丧偶。
     */
    //@NotBlank(message = "婚姻情况不能为空")
    @Schema(description = "UNMARRIED=未婚,MARRIED=已婚,DIVORCED=离婚,WIDOWED=丧偶")
    @Excel(name = "婚姻情况", readConverterExp = "UNMARRIED=未婚,MARRIED=已婚,DIVORCED=离婚,WIDOWED=丧偶")
    private String marriageCondition;

    /**
     * 儿女情况
     */
//    @Excel(name = "儿女情况")
    private String childrenCondition;

    /**
     * 儿女情况-女孩 children_condition_girl
     */
    @Excel(name = "儿女情况-男孩数量")
    private Integer childrenConditionGirl;

    /**
     * 儿女情况-男孩 children_condition_boy
     */
    @Excel(name = "儿女情况-女孩数量")
    private Integer childrenConditionBoy;

    /**
     * 用户专属头像地址
     */
    private String exclusiveAvatar;

    /**
     * 专属头像审核状态 0-审核中;1-审核通过;2-审核拒绝
     */
    private String exclusiveAvatarStatus;

    /**
     * 审核结果
     */
    private String processResult;

    /**
     * 被沟通人的快乐值
     */
    // @TableField(exist = false)
    private Integer happinessScore;

    /**
     * 快乐豆
     */
    // @TableField(exist = false)
    private Integer hlbean;

    /**
     * 近几日被沟通过
     */
    // @TableField(exist = false)
    private Integer communicateCount;

    // @TableField(exist = false)
    private String deptName;

    public SysUserDTO() {

    }

    public SysUserDTO(Long userId) {
        this.userId = userId;
    }
//
//    public boolean isAdmin() {
//        return isAdmin(this.userId);
//    }
//
//    public static boolean isAdmin(Long userId) {
//        return userId != null && 1L == userId;
//    }

    public static SysUserDTO iconv(SysUser sysUser) {
        return BeanUtils.copyPropsIgnoreNull(sysUser, new SysUserDTO());
    }
}
